//
//  TCLYHeaderView.m
//  YuErmuYing
//
//  Created by LYang on 16/8/11.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYHeaderView.h"
#import "Masonry.h"


#define WIDTH [UIScreen mainScreen].bounds.size.width
@implementation TCLYHeaderView
-(instancetype) initWithFrame:(CGRect)frame IntegralLabelText:(NSString *)integralText SignInLabelText:(NSString *)signInText CashLabelText:(NSString *)cashText{
    if (self = [super initWithFrame:frame]) {
        //我的界面头像下方的背景图片
        UIImageView * bgHeaderImageView = [[UIImageView alloc] init];
        bgHeaderImageView.image = [UIImage imageNamed:@"bgHeader"];
        [self addSubview:bgHeaderImageView];
        [bgHeaderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self);
            make.left.mas_equalTo(self);
            make.right.mas_equalTo(self);
            make.bottom.mas_equalTo(self);
        }];
        //我的界面显示头像图片的ImageView
        self.headerImageView = [[UIImageView alloc] init];
        self.headerImageView.layer.cornerRadius = 30;
        self.headerImageView.layer.masksToBounds = YES;
        [self addSubview:self.headerImageView];
        [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.top.mas_equalTo(30);
            make.width.mas_equalTo(60);
            make.height.mas_equalTo(60);
        }];
        //头像下方的昵称label
        self.nickNameLabel = [[UILabel alloc] init];
        self.nickNameLabel.textColor = [UIColor blackColor];
        self.nickNameLabel.textAlignment = NSTextAlignmentCenter;
        self.nickNameLabel.font = [UIFont boldSystemFontOfSize:22];
        [self addSubview:self.nickNameLabel];
        [self.nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.headerImageView.mas_bottom).offset(12);
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.height.mas_equalTo(24);
        }];
        
        //昵称下方的带有透明度的bgImageView
        UIImageView * bgImageView = [[UIImageView alloc] init];
        bgImageView.backgroundColor = [UIColor blackColor];
        bgImageView.alpha = 0.2;
        [self addSubview:bgImageView];
        [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nickNameLabel.mas_bottom).offset(12);
            make.left.mas_equalTo(self);
            make.right.mas_equalTo(self);
            make.height.mas_equalTo(50);
        }];
        //显示积分的label
        self.integralLabel = [[UILabel alloc] init];
        self.integralLabel.textColor = [UIColor whiteColor];
        self.integralLabel.textAlignment = NSTextAlignmentCenter;
        self.integralLabel.font = [UIFont systemFontOfSize:16];
        self.integralLabel.numberOfLines = 1;
        self.integralLabel.text = integralText;
        self.integralLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        CGSize integralLabelMaximumLabelSize = CGSizeMake(100, 16);//labelsize的最大值
        CGSize integralLabelExpectSize = [self.integralLabel sizeThatFits:integralLabelMaximumLabelSize];
        [self addSubview:self.integralLabel];
        [self.integralLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.top.mas_equalTo(bgImageView.mas_top).offset(6);
            make.width.mas_equalTo(integralLabelExpectSize.width);
            make.height.mas_equalTo(16);
        }];
        UILabel * integral = [[UILabel alloc] init];
        integral.textColor = [UIColor whiteColor];
        integral.textAlignment = NSTextAlignmentCenter;
        integral.font = [UIFont systemFontOfSize:16];
        integral.text = @"积分";
        [self addSubview:integral];
        [integral mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(40);
            make.height.mas_equalTo(self.integralLabel);
            make.bottom.mas_equalTo(bgImageView.mas_bottom).offset(-6);
            make.centerX.mas_equalTo(self);
        }];
        //显示现金的Label
        self.cashLabel = [[UILabel alloc] init];
        self.cashLabel.textColor = [UIColor whiteColor];
        self.cashLabel.textAlignment = NSTextAlignmentCenter;
        self.cashLabel.font = [UIFont systemFontOfSize:16];
        self.cashLabel.numberOfLines = 1;
        self.cashLabel.text = cashText;
        self.cashLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        CGSize cashLabelMaximumLabelSize = CGSizeMake(100, 12);//labelsize的最大值
        CGSize cashLabelExpectSize = [self.cashLabel sizeThatFits:cashLabelMaximumLabelSize];
        [self addSubview:self.cashLabel];
        [self.cashLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(30);
            make.width.mas_equalTo(cashLabelExpectSize.width);
            make.top.mas_equalTo(self.integralLabel);
            make.height.mas_equalTo(self.integralLabel);
        }];
        UILabel * cash = [[UILabel alloc] init];
        cash.textColor = [UIColor whiteColor];
        cash.textAlignment = NSTextAlignmentCenter;
        cash.font = [UIFont systemFontOfSize:16];
        cash.text = @"现金";
        [self addSubview:cash];
        [cash mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.cashLabel);
            make.height.mas_equalTo(self.cashLabel);
            make.bottom.mas_equalTo(bgImageView.mas_bottom).offset(-6);
            make.width.mas_equalTo(40);
        }];
        //显示签到的label
        self.signInLabel = [[UILabel alloc] init];
        self.signInLabel.textColor = [UIColor whiteColor];
        self.signInLabel.textAlignment = NSTextAlignmentCenter;
        self.signInLabel.font = [UIFont systemFontOfSize:16];
        self.signInLabel.numberOfLines = 0;
        self.signInLabel.text = signInText;
        self.signInLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        CGSize signInLabelMaximumLabelSize = CGSizeMake(100, 12);//labelsize的最大值
        CGSize signInLabelExpectSize = [self.signInLabel sizeThatFits:signInLabelMaximumLabelSize];
        [self addSubview:self.signInLabel];
        [self.signInLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-30);
            make.width.mas_equalTo(signInLabelExpectSize.width);
            make.top.mas_equalTo(self.integralLabel);
            make.height.mas_equalTo(16);
        }];
        UILabel * signIn = [[UILabel alloc] init];
        signIn.textColor = [UIColor whiteColor];
        signIn.textAlignment = NSTextAlignmentCenter;
        signIn.font = [UIFont systemFontOfSize:16];
        signIn.text = @"签到";
        [self addSubview:signIn];
        [signIn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(40);
            make.height.mas_equalTo(self.signInLabel);
            make.bottom.mas_equalTo(bgImageView.mas_bottom).offset(-6);
            make.centerX.mas_equalTo(self.signInLabel);
        }];
        
        self.newsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.newsBtn setImage:[UIImage imageNamed:@"LYLetter"] forState:UIControlStateNormal];
        [self addSubview:self.newsBtn];
        [self.newsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.mas_right).offset(-12);
            make.top.mas_equalTo(self.mas_top).offset(6);
            make.width.mas_equalTo(25);
            make.height.mas_equalTo(30);
        }];
    }
    return self;
}
@end
